/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, {Component} from 'react';
import {
    Image,
    TextInput,
    AppRegistry,
    StyleSheet,
    ProgressBarAndroid,
    Text,
    View,
    TouchableOpacity,
    Alert,
    ToastAndroid
} from 'react-native';
import NetworkTool,{fetchPostRequest} from '../../../util/network/NetworkTool'
import store from 'react-native-simple-store'
export default class LoginScene extends Component {
    render() {
        return (
            <View style={styles.container}>
                <Image style={{width: 70, height: 70, alignSelf: 'center', marginTop: 30}}
                       source={require('../../../../res/img/mine/aboutus.png')}/>
                <TextInput style={styles.name}
                           placeholder={'QQ号/手机号/邮箱'}
                           numberOfLines={1}
                           underlineColorAndroid={'transparent'}
                           autoFocus={false}
                           textAlign="center"/>
                <View style={{height: 1, backgroundColor: '#f4f4f4'}}/>
                <TextInput style={styles.password}
                           placeholder={'密码'}
                           numberOfLines={1}
                           underlineColorAndroid={'transparent'}
                           secureTextEntry={true}
                           textAlign="center"
                />
                <View style={styles.login}>
                    <TouchableOpacity onPress={()=>this.login()}>
                        <Text style={{ color:'white'}}>登  录</Text>
                    </TouchableOpacity>
                </View>
                <View style={{flexDirection: 'row', marginTop: 13, alignItems: 'flex-end'}}>
                    <Text style={{marginLeft: 10, color: 'gray'}}>
                        忘记密码？
                    </Text>
                    <Text style={{
                        marginRight: 10,
                        color: 'gray',
                        alignItems: 'flex-end',
                        textAlign: 'right',
                        flex: 1
                    }}>
                        新用户注册
                    </Text>
                </View>
            </View>
        );
    }

    login() {

        let REQUEST_URL = 'https://i.jkzaixian.com/api/rest/smscode/';

        let parameters = new FormData();
        parameters.append("mobile", "15011518253");
        parameters.append("for", "register");

        fetch(REQUEST_URL, {
            method: 'POST',
            body: parameters
        }).then(
            (result) => {
                ToastAndroid.show(result.json, ToastAndroid.SHORT)
            }
        ).catch((error) => {
            console.log(error)
            Alert.alert('Error')
        })

    }
}

const styles = StyleSheet.create({
        container: {
            flex: 1,
            backgroundColor: '#F4F4F4',
        },
        name: {
            backgroundColor: '#FFF',
            height: 50,
            marginTop: 10,
            fontSize: 15,
        },
        password: {
            backgroundColor: '#FFF',
            height: 50,
            fontSize: 15,
        },
        login: {
            height: 40,
            marginLeft: 10,
            marginRight: 10,
            backgroundColor: '#DB3843',
            marginTop: 15,
            alignItems: 'center',
            justifyContent: 'center',
            borderRadius: 5,
        },
    })
    ;
